<template>
	<view>
		<view class="subsection-box" style="justify-content: center;color: #ffffff;">
			{{getStr('myBag.selectCart')}}
		</view>

		<!-- <view class="subsection-box">
			<view :class="selectSubsection == item ? 'item active' : 'item'" @click="handleSelectSubsection(item,index)"
				v-for="(item,index) in list" :key="index">
				{{getStr('starPond.index.' + item)}}
			</view>
		</view> -->
		<!-- <view class="tab-box">
			<view :class="selectTab == item ? 'item active' : 'item'" @click="selectTab = item"
				v-for="(item,index) in tabList" :key="index">
				{{item}}
			</view>(
		</view> -->

		<view class="list-box">
			<view class="item good-bg1" v-for="(item,index) in goods" @click="handleGoods(item)">
				<view class="start-box">
					可出售
				</view>
				<view class="item-info">
					<image src="/static/images1/kapai.png"
						style="width: 146rpx; height: 225rpx;border-radius: 12rpx;margin: 0 auto;"></image>
					<view class="title" style="margin-bottom: 28rpx;">{{item.zhName}}</view>
					<!-- <view class="des">{{item.nickName}}</view> -->
					<!-- <view class="hour-box">
						<text>{{item.price}}</text>
						<image src="/static/images1/star-bb.png"
							style="width: 18rpx; height: 18rpx;margin: 0 6rpx 0 2rpx;"></image>
					</view> -->
					<!-- <view class="bottom-box">
						<view>
							<text>{{getStr('trade.issuePrice')}}:{{item.releasePrice}}</text>
							<image src="/static/images1/star-bb.png"
								style="width: 18rpx; height: 18rpx;margin: 0 6rpx 0 2rpx;">
							</image>
						</view>
						<view>
							<text>{{getStr('trade.lastPrice')}}:{{item.lastPrice}}</text>
							<image src="/static/images1/star-bb.png"
								style="width: 18rpx; height: 18rpx;margin: 0 6rpx 0 2rpx;">
							</image>
						</view>
					</view> -->
				</view>
				<!-- <view class="divider-box"><up-divider text="" lineColor="#FFFFFF50"></up-divider></view>
				<view class="item-buttom">
					<text>{{item.turnoverNumber}}次</text>
					<text>+{{item.cardGrowthRate * 100}}%</text>
				</view> -->
				<!-- <view class="item-info">
					<image :src="item.img" style="width: 180rpx; height: 130rpx;border-radius: 12rpx;margin: 0 auto;">
					</image>
					<view class="title">{{item.zhName}}</view>
					<view class="des">{{item.cardType}}</view>
					<view class="hour-box">
						Profit per hour
						<image :src="zsImg" style="width: 28rpx; height: 28rpx;margin: 0 6rpx 0 2rpx;"></image>
						<text>+{{item.cardGrowthRate * 100}}%</text>
					</view>
				</view>
				<view class="divider-box"><up-divider text="" lineColor="#FFFFFF50"></up-divider></view>
				<view class="item-buttom">
					Ivl {{item.ivl}}
					<image :src="zsImg" style="width: 28rpx; height: 28rpx;margin: 0 6rpx 0 34rpx;"></image>
					<text>+{{item.currentPrice}}</text>
				</view> -->
			</view>

		</view>

		<view class="popup-box">
			<up-popup :show="popupShow" @close="popupShow = false" @open="open">
				<view class="popup">
					<view class="close-box">
						<image src="/static/images1/close-icon.png" style="width: 26rpx; height: 26rpx;"></image>
					</view>
					<view class="image-box">
						<image :src="selectGoods.img" style="width: 340rpx; height: 240rpx;border-radius: 12rpx;">
						</image>
					</view>
					<view class="title-box">Hamster Biker</view>
					<view class="des-box">With his leather jacket and custom bike, this hamster blazesth</view>
					<view class="des-box">Profit per hour</view>
					<view class="price-box1">
						<image :src="zsImg" style="width: 28rpx; height: 28rpx;margin-right: 10rpx;"></image>
						+0.024
					</view>
					<view class="price-box2">
						<image :src="zsImg" style="width: 42rpx; height: 42rpx;margin-right: 14rpx;"></image>
						70.18
					</view>
					<view class="btn-box">
						<u-button customStyle="border-radius:12rpx;height:100rpx;font-weight: 500;font-size: 32px;color: #FFFFFF;"
							text="Expired" color="#262930" @click="()=>{}"></u-button>
					</view>
				</view>
			</up-popup>
		</view>

		<confirmModal :show="modalShow" :describe="getStr('prompt')"
			@close="()=>{modalShow = false;selectGoods = {}}" @confirm="confirm"></confirmModal>
	</view>
</template>

<script setup>
	import defaultImg from '@/static/default-img.png'
	import zsImg from '@/static/zs.png'
	import confirmModal from '@/components/confirmModal/index.vue'
	import {
		ref
	} from 'vue';
	import {
		onShow,
		onLoad,
		onPullDownRefresh,
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		getAdSellList,
		adSell
	} from '@/common/api/common.js'

	const modalShow = ref(false)

	const source = ref('')
	const cardInfo = ref('')

	// const list = ref(['upperFour', 'middleFour', 'lowerFour'])
	const list = ref(['games', 'minigames', 'mineCards'])
	// const tabList = ref(['My cards', 'New cards', 'Missed opportunities'])
	const selectSubsection = ref('games')
	// const selectTab = ref('My cards')
	const isRender = ref(false)
	const popupShow = ref(false)
	const selectGoods = ref({})
	const page = ref(1)
	const totalPages = ref(1)
	const adId = ref('')

	const goods = ref([])

	const handleGoods = async (data) => {
		modalShow.value = true
		selectGoods.value = data
	}

	const confirm = async () => {
		const res = await adSell({
			telegramId: uni.getStorageSync('telegramId'),
			adId: adId.value,
			userCardId: selectGoods.value.userCardId
		})
		if (res.code == 200) {
			uni.$u.toast(getStr('toast.successfully'))
			goPage('/pages/my/detailOfAssets/index')
		} else {
			uni.$u.toast(res.message)
		}
	}

	const handleSelectSubsection = (data, index) => {
		selectSubsection.value = data
		totalPages.value = 1
		page.value = 1
		getMyBagFn()
	}

	const getMyBagFn = async () => {
		const res = await getAdSellList({
			telegramId: uni.getStorageSync('telegramId'),
			adId: adId.value,
		})
		if (res.code == 200) {
			goods.value = res.data
			totalPages.value = res.data.totalPages
		}
	}

	const goPage = (url) => {
		uni.navigateTo({
			url: url
		})
	}

	const getStr = (key) => {
		return uni.$t(key)
	}
	const setIsRender = () => {
		isRender.value = false
		setTimeout(() => {
			isRender.value = true
		}, 50)
	}
	onLoad((options) => {
		if (options.selectSubsection && options.adId) {
			const data = {
				games: 'upperFour',
				minigames: 'middleFour',
				mineCards: 'lowerFour'
			}

			selectSubsection.value = options.selectSubsection
			adId.value = options.adId
		}
		getMyBagFn()
	})
	onShow(() => {
		uni.$tg.showButton()
		setIsRender()
		getMyBagFn()
	})
	onReachBottom(() => {
		if (pages.value + 1 <= totalPages.value) {
			pages.value = pages.value + 1
			getTradeListFn()
		}
	})
</script>
<style>
	page {
		background: #1C1E23;
	}
</style>
<style lang="scss" scoped>
	.subsection-box {
		width: calc(100vw - 28rpx - 28rpx);
		height: 84rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #272A2F;
		border-radius: 12rpx;
		padding: 8rpx;
		box-sizing: border-box;
		margin: 28rpx auto 0;

		.item {
			width: 33.33%;
			height: calc(84rpx - 8rpx - 8rpx);
			color: #ffffff;
			border-radius: 12rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.active {
			background: #1C1F24;
		}
	}

	.tab-box {
		width: calc(100vw - 28rpx - 28rpx);
		display: flex;
		justify-content: flex-start;
		align-items: center;
		margin: 22rpx auto 0;
		border-bottom: 1px solid #272A2F;

		.item {
			padding: 20rpx 0;
			color: #ffffff;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 22rpx;
			margin-right: 30rpx;
			border-bottom: 1px solid #000000;
		}

		.active {
			color: #DCBB4F;
			border-bottom: 1px solid #DCBB4F;
		}
	}

	.list-box {
		padding: 32rpx 28rpx 100rpx;
		display: flex;
		// justify-content: space-between;
		flex-wrap: wrap;


		.item:nth-child(2n) {
			background: linear-gradient(0deg, #453337 0%, #F0B4C1 100%);
			margin-right: 0;
		}

		.item:nth-child(2n-1) {
			background: linear-gradient(0deg, #25251D 0%, #F7F1CD 100%);
		}

		.item:nth-child(1) {
			background: linear-gradient(0deg, #13222D 0%, #5599C0 100%);
		}

		.item:nth-child(2) {
			background: linear-gradient(0deg, #271F2A 0%, #D4B6EB 100%);
		}

		.item:nth-child(3) {
			background: linear-gradient(0deg, #453337 0%, #F0B4C1 100%);
		}

		.item:nth-child(4) {
			background: linear-gradient(0deg, #25251D 0%, #F7F1CD 100%);
		}

		.item {
			width: 338rpx;
			// height: 398rpx;
			box-sizing: border-box;
			padding-top: 72rpx;
			background: linear-gradient(0deg, #25251D 0%, #F7F1CD 100%);
			border-radius: 32rpx;
			margin-bottom: 18rpx;
			margin-right: 18rpx;
			position: relative;

			.start-box {
				padding: 0 20rpx;
				height: 42rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				position: absolute;
				right: 0;
				top: 0;
				background: #00000080;
				border-top-right-radius: 32rpx;
				border-bottom-left-radius: 32rpx;
				color: #ffffff;
				font-size: 16rpx;

				::v-deep .u-count-down__text {
					color: #ffffff;
					font-size: 16rpx;
					line-height: 28px;
				}
			}

			.item-info {
				display: flex;
				flex-direction: column;
				align-content: center;

				.title {
					font-weight: 800;
					font-size: 20rpx;
					line-height: 20rpx;
					color: #FFFFFF;
					margin-top: 12rpx;
					text-align: center;
				}

				.des {
					font-weight: 500;
					font-size: 16rpx;
					line-height: 16rpx;
					color: #FFFFFF;
					opacity: 0.5;
					margin-top: 12rpx;
					text-align: center;
				}

				.hour-box {
					font-weight: 500;
					font-size: 14rpx;
					line-height: 14rpx;
					color: #FFFFFF80;
					display: flex;
					justify-content: center;
					align-items: center;
					margin-top: 12rpx;

					text {
						// font-size: 20rpx;
						font-weight: bold;
						font-size: 24rpx;
						color: #FFFFFF;
						margin-right: 4rpx;
					}
				}

				.bottom-box {
					width: calc(100% - 28rpx - 28rpx);
					margin: 20rpx auto 0;
					display: flex;
					justify-content: space-between;
					align-items: center;

					view {
						font-size: 14rpx;
						color: #FFFFFF80;
						display: flex;
						justify-content: flex-start;
						align-items: center;
					}

					text {
						margin-right: 2rpx;
					}
				}

			}

			.divider-box {
				width: calc(100% - 28rpx - 28rpx);
				margin: 10rpx auto 10rpx;

				::v-deep .u-divider {
					margin: 0;
				}
			}

			.item-buttom {
				width: calc(100% - 28rpx - 28rpx);
				margin: 0 auto 30rpx;
				line-height: 20rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-weight: bold;
				font-size: 18rpx;
				color: #FFFFFF;
			}

		}
	}

	.popup-box {

		::v-deep .u-popup__content {
			// height: calc(100vh - 138rpx - 42rpx - 64rpx);
			background: #1C1E23;
			padding-bottom: 42rpx;
			border-top-left-radius: 60rpx;
			border-top-right-radius: 60rpx;
			box-shadow: 0 0 20px rgba(218, 168, 183, 0.6),
				/* 主外发光 */
				0 0 20px rgba(218, 168, 183, 0.2),
				/* 次外发光 */
				0 0 20px rgba(218, 168, 183, 0.1);
			/* 远离中心的外发光 */
			border-top: 1px solid #DAA8B7;
		}

		.close-box {
			width: 26rpx;
			height: 26rpx;
			position: absolute;
			right: 42rpx;
			top: 42rpx;
		}

		.image-box {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-top: 42rpx;
		}

		.title-box {
			font-weight: bold;
			font-size: 48rpx;
			color: #FFFFFF;
			text-align: center;
			margin-top: 30rpx;
			line-height: 48rpx;
		}

		.des-box {
			width: calc(100% - 105rpx - 105rpx);
			margin: 30rpx auto 0;
			font-weight: 500;
			font-size: 24rpx;
			line-height: 26rpx;
			color: #FFFFFF;
			text-align: center;
		}

		.price-box1 {
			display: flex;
			justify-content: center;
			align-items: center;
			opacity: 0.5;
			margin-top: 30rpx;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 20rpx;
		}

		.price-box2 {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-top: 30rpx;
			font-weight: bold;
			font-size: 48rpx;
			line-height: 48rpx;
			color: #FFFFFF;
		}

		.btn-box {
			width: calc(100% - 28rpx - 28rpx);
			margin: 48rpx auto 0;
		}
	}
</style>